﻿@{
    ViewBag.Title = "Ins";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js?ver=GetDate()")" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">
    
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-search" onclick="LoadData" plain="true">刷新</a>
                    <a class="mini-button" iconCls="icon-goto" onclick="clearloca" plain="true">重置</a>                
                    <a class="mini-button" id="export" iconCls="icon-node" onclick="setExportExcel('datagrid1')" plain="true" visible="@ViewBag.export">导出</a>
                    <a class="mini-button" iconCls="icon-edit" onclick="sendToPur" plain="true" visible="@ViewBag.sendtopur">生成采购单</a>
                    <span class="separator"></span>-
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>                
    </div>
    
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">转单状态：</td>
                <td width ="87px">
                    <input id="comSendType" name ="FSendType" class="mini-combobox" style="width:87px;" 
                    showNullItem="false" required="true" allowInput="false" value ="1" align="left" data ="dSendType"/>  
                </td>
                <td width ="73px" align="right"></td>
                <td width ="150px">                
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <td width ="70px" align="right">供应商：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookUpSupply.cshtml")                       
                </td>
                <td width ="70px" align="right">门店名称：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")                      
                </td>
                <td width ="70px" align="right">单据编号：</td>
                <td width ="150px">
                    <input name="FBillNo" class="mini-textbox" style="width:150px;"/>
                </td>
            </tr>
            <tr>
                <td width ="70px" align="right">商品分类：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupGoodsClass.cshtml")                       
                </td>
                <td width ="70px" align="right">商品品牌：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupGoodsBrand.cshtml")                      
                </td>
                <td width ="70px" align="right">商品搜索：</td>
                <td width ="150px">
                    <input name="FNumber" class="mini-textbox" style="width:150px;"/>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" borderStyle="border:1;"pageSize="100"
            url="../BillTransfer/GetPraToPurList"
            allowCellSelect="true" allowCellEdit="true" showSummaryRow="true" ondrawsummarycell="onDrawSummaryCell"
            multiSelect="true" fitColumns="false" sortMode="client">
            <div property="columns">
                <div type="checkcolumn" ></div>  
                <div field="FBillNo" width="120" headerAlign="center">单据编号</div>    
                <div field="FDate" width="90px" headerAlign="center">单据日期</div> 
                <div field="FNumber" width="90" headerAlign="center">商品编码</div>
                <div field="FName" width="130" headerAlign="center">商品名称</div>
                <div field="FSpec" width="80" headerAlign="center">规格型号</div>
                <div field="FUnitName" width="40" headerAlign="center">单位</div>
                <div field="mFQty" name="mFQty" width="70" headerAlign="center"align="right"numberFormat="#,0.00">要货数量</div>                
                <div field="mFPrice" name="mFPrice" width="70" headerAlign="center"align="right"numberFormat="#,0.00">配送单价</div>
                <div field="mFAmount" name="mFAmount" width="90" headerAlign="center"align="right"numberFormat="#,0.00">配送金额</div>
                <div field="FPurPrice" name="FPurPrice" width="70" headerAlign="center"align="right"numberFormat="#,0.00">采购单价</div>
                <div field="mFQty_Pur" name="mFQty_Pur" width="70" headerAlign="center"align="right"numberFormat="#,0.00">已采购数量</div>
                <div field="mFAmount_Pur" name="mFAmount_Pur" width="90" headerAlign="center"align="right"numberFormat="#,0.00">已采购金额</div>
                <div field="mFQty_PurUn" name="mFQty_PurUn" width="70" headerAlign="center"align="right"numberFormat="#,0.00">未采购数量</div>
                <div field="mFAmount_PurUn" name="mFAmount_PurUn" width="90" headerAlign="center"align="right"numberFormat="#,0.00">未采购金额</div>
                <div field="FCode" width="100" headerAlign="center">商品条码</div>
                <div field="FSuppNumber" width="150" headerAlign="center">供应商名称</div>
                <div field="FSuppName" width="150" headerAlign="center">供应商名称</div>
                <div field="FGetStockName" width="100" headerAlign="center">门店名称</div>
                <div field="FUserName" width="80" headerAlign="center">用户名称</div>
                <div field="mFRemark" width="120" headerAlign="center">备注</div>
            </div>
        </div>  
    </div>
    
    <script type="text/javascript">


        var dSendType = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "未转单" },
                         { "id": "2", "text": "已转单" }]

        mini.parse();
        var form = new mini.Form("form1");
        var grid = mini.get("datagrid1");
        var uID = parent.window.getSystemAppID();
        var sumFields = "mFQty,mFAmount,mFQty_Pur,mFAmount_Pur,mFQty_PurUn,mFAmount_PurUn";

        function FormShown() {
            var nowDate = new Date();
            mini.getbyName("FDate1").setValue(nowDate);
            mini.getbyName("FDate2").setValue(nowDate);
            mini.getbyName("FSendType").select(1);
            LoadData();
            InitGrid('BllDetailIns');
        }

        function clearloca() {
            mini.getbyName("FStockID").setValue("");
            mini.getbyName("FStockID").setText("");
            mini.getbyName("FStockName").setValue("");
            mini.getbyName("FSupplyItemID").setValue("");
            mini.getbyName("FSupplyItemID").setText("");
            mini.getbyName("FSupplyName").setValue("");
            mini.getbyName("FClassNumber").setValue("");
            mini.getbyName("FClassNumber").setText("");
            mini.getbyName("FGoodsClassName").setValue("");
            mini.getbyName("FBrandItemID").setValue("");
            mini.getbyName("FBrandItemID").setText("");
            mini.getbyName("FBrandName").setValue("");
            mini.getbyName("FBillNo").setValue("");
            mini.getbyName("FNumber").setValue("");
        }

        function LoadData() {
            var cDate1 = mini.getbyName("FDate1").getFormValue();
            var cDate2 = mini.getbyName("FDate2").getFormValue();
            var mSendType = mini.getbyName("FSendType").getValue();
            var mBillNo = mini.getbyName("FBillNo").getValue();
            var mStockID = mini.getbyName("FStockID").getValue();
            var mSupplyID = mini.getbyName("FSupplyItemID").getValue();
            var mClassID = mini.getbyName("FClassNumber").getValue();
            var mBrandID = mini.getbyName("FBrandItemID").getValue();
            var mNumber = mini.getbyName("FNumber").getValue();

            var json = "[{";
            json = json + '"mListType":' + '"' + "-8" + '",';//列表类型
            json = json + '"mSystemAppID":' + '"' + uID + '",';
            json = json + '"mDate1":' + '"' + cDate1 + '",';
            json = json + '"mDate2":' + '"' + cDate2 + '",';
            json = json + '"mSendType":' + '"' + mSendType + '",';
            json = json + '"mStockID":' + '"' + mStockID + '",';
            json = json + '"mSupplyID":' + '"' + mSupplyID + '",';
            json = json + '"mClassID":' + '"' + mClassID + '",';
            json = json + '"mBrandID":' + '"' + mBrandID + '",';
            json = json + '"mNumber":' + '"' + mNumber + '",';
            json = json + '"mBillNo":' + '"' + mBillNo + '"';
            json = json + "}]";

            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;//导出
        }

        function sendToPur(){
            var row = grid.getSelected();
            if (row) {
                sendToPurTo();
            } else {
                mini.alert("请选要转单的数据");
            }

        }

        function sendToPurTo() {
            var rows = grid.getSelecteds();
            var json = "[";
            for (var i = 0; i < rows.length; i++) {
                if (i > 0) json = json + ',';
                js = '{"mFEntryID":' + rows[i].mFEntryID + '}';
                json = json + js;
            }
            json = json + "]";
            if (json.length < 8) {
                mini.alert("请选要转单的数据！");
                return;
            }
            $.post("SetPraToPurBill", { json: json, mSystemAppID: uID }, function (data) {
                var ret = mini.decode(data);
                if (ret.id > 0) {
                    parent.window.showTabByIdEx('193','PurData', '采购订货单', '../Bill/PurData?datatype=-8&billid=' + ret.id);
                    grid.reload();
                }
                else {
                    mini.alert("异常:" + ret.Status);
                }
            });
        }

        function printdata() {
            var url = "../Report/PrintReport";
            mini.open({
                url: url,
                title: "打印", width: 1000, height: 700,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var NoneDisplayCol = [0];
                    iframe.contentWindow.InitalPrint(grid, NoneDisplayCol,parent.window.getSystemCompany()+"采购明细表");
                }
            });
        }

    </script>

    </form>
</body>